package com.smartpro.mis.modular.system.dao;

import com.smartpro.mis.modular.business.neo4jEntity.DealFinishRelationship;
import com.smartpro.mis.modular.business.neo4jEntity.DistributorExpireRelationship;
import com.smartpro.mis.modular.business.neo4jEntity.N4jDistributor;
import com.smartpro.mis.modular.business.neo4jEntity.N4jUser;
import org.springframework.data.neo4j.annotation.Query;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.repository.query.Param;
import org.springframework.data.rest.core.annotation.RepositoryRestResource;

import java.util.Collection;

/**
 * @author Mengiy
 */
@RepositoryRestResource(collectionResourceRel = "distributorExpireRelationship", path = "distributorExpireRelationship")
public interface DistributorExpireRelationRepository extends Neo4jRepository<DistributorExpireRelationship, Long> {

    @Query("MATCH (m:DistributorExpireRelationship) where m.n4jUser = {n4jUser} RETURN m limit 1")
    DistributorExpireRelationship findExpireRelationByN4jUser(@Param("n4jUser") N4jUser n4jUser);

    //更新绑定关系
    @Query("match(n) where n.id = {id} set n.createTime={createTime},n.expire={expire},n.n4jDistributor={n4jDistributor},n.n4jUser={n4jUser} return n")
    DistributorExpireRelationship updateRelationById(@Param("id") Long id, @Param("createTime")String createTime, @Param("expire")int expire, @Param("n4jDistributor")N4jDistributor n4jDistributor,@Param("n4jUser")N4jUser n4jUser);
}